package leetcode;


/**
 * Created by Ghost on 2014/12/13.
 */
public class Rotate_Image {
    public void rotate(int[][] matrix) {
        if(matrix==null || matrix.length==0)
            return;
        int n = matrix.length;
        int start = 0;
        while(n>1){

            for(int i=start;i<matrix.length-1-start;i++){
                int tmp = matrix[start][i];
                matrix[start][i] = matrix[matrix.length-1 - i][start];
                matrix[matrix.length-1-i][start] = matrix[matrix.length-1 - start][matrix.length-1-i];
                matrix[matrix.length-1 - start][matrix.length-1-i] = matrix[i][matrix.length-1-start];
                matrix[i][matrix.length-1-start]= tmp;
            }
            n-=2;
            start++;
        }
    }
    public static void main(String[] args){
        Rotate_Image rotate_image = new Rotate_Image();
        int[][] matrix = {{1}};
        rotate_image.rotate(matrix);
        for(int i=0;i<matrix.length;i++){
            for(int j=0;j<matrix.length;j++){
                System.out.print(" "+matrix[i][j]);
            }
            System.out.println();
        }
    }
}
